//
//  SelectPollingView.m
//  OperationPro
//
//  Created by yaxue wang on 2017/1/9.
//  Copyright © 2017年 展鸿科技. All rights reserved.
//

#import "SelectPollingView.h"

@interface SelectPollingView()
@property(nonatomic)NSInteger selectNum;


@end
@implementation SelectPollingView
-(instancetype)initWithFrame:(CGRect)frame { //withFirst:(NSString*)first withSecond:(NSString*)second{
    self = [super initWithFrame:frame];
    if (self) {
        _selectNum=0;
        UIImage *img=[UIImage imageNamed:@"Ico_input_NoSelect"];
        _firstBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _firstBtn.frame=CGRectMake(10, 0, img.size.width+10+36, img.size.height);
        [_firstBtn setImage:img forState:UIControlStateNormal];
        [_firstBtn setTitleColor:C(@"585858") forState:UIControlStateNormal];
        _firstBtn.titleLabel.font=F(15);
        [_firstBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0,0)];
        [_firstBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -img.size.width)];
        [self addSubview:_firstBtn];
        
       _secondBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _secondBtn.frame=CGRectMake(125, 0, img.size.width+10+36, img.size.height);
        [_secondBtn setImage:img forState:UIControlStateNormal];
        [_secondBtn setTitleColor:C(@"585858") forState:UIControlStateNormal];
        _secondBtn.titleLabel.font=F(15);
        [_secondBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0,0)];
        [_secondBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -img.size.width)];
        [self addSubview:_secondBtn];
        
        [_firstBtn bk_addEventHandler:^(id sender) {
            _selectNum=1;
            [_firstBtn setImage:[UIImage imageNamed:@"Ico_input_select"] forState:UIControlStateNormal];
            [_secondBtn setImage:img forState:UIControlStateNormal];
            NSString* selectString=[NSString stringWithFormat:@"%d",_selectNum];
            if(self.selectBtnClick){
                self.selectBtnClick(selectString);
            }
        
        } forControlEvents:UIControlEventTouchUpInside];

        [_secondBtn bk_addEventHandler:^(id sender) {
            _selectNum=2;
            [_secondBtn setImage:[UIImage imageNamed:@"Ico_input_select"] forState:UIControlStateNormal];
            [_firstBtn setImage:img forState:UIControlStateNormal];
            NSString* selectString=[NSString stringWithFormat:@"%d",_selectNum];
            if(self.selectBtnClick){
                self.selectBtnClick(selectString);
            }

        } forControlEvents:UIControlEventTouchUpInside];


        
        
    }
    return self;
    
}
- (void)setFirst:(NSString *)first
{
    [_firstBtn setTitle:self.first forState:UIControlStateNormal];

}
- (void)setSecond:(NSString *)second
{
    [_secondBtn setTitle:self.second forState:UIControlStateNormal];

}
@end
